library(dplyr)
library(tidyverse)
library(ggplot2)
library(sf)
library(tigris)
library(stringr)
library(grid)
library(gtable)
library(kableExtra)
fp <- "/Users/alisabethmarsteller/American Violence Dropbox/Alisabeth Marsteller/ChicagoLawReview_Symposium/shootings_allcities"
source(paste0(fp, "/R/functions.R"))
files <- list.files(paste(fp,"data/combined_data/", sep="/"), pattern=".csv")
df_list <- list()
for (fn in files) {
df <- read.csv(paste(fp,"data/combined_data", fn, sep="/")) %>%
mutate(geoid = str_pad(geoid, 11, side="left", pad="0")) %>%
filter(year < 2021)
df_list <- append(df_list, list(df))
}
df <- bind_rows(df_list, .id = NULL)
p1 <- ggplot(subdf[[1]]) +
geom_sf(aes(fill=fatal_shootings), size=0.01) +
facet_wrap(~year, ncol = 1, labeller = labeller(VAR = "year")) +
theme_minimal() +
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
panel.grid.major = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
legend.key.size = unit(0.6, 'cm'),
legend.text = element_text(size=8),
strip.text = element_text(size=14)) +
scale_fill_gradient(low = "white", high = "indianred4", limits=c(0,62))
tracts_df <- tracts(state = "IL", year=2019, cb=TRUE)
tracts_df <- st_as_sf(tracts_df) %>% st_transform(crs=4326)
homs_rates <- tracts_df %>%
unite("tractname", STATEFP, COUNTYFP, TRACTCE, sep="") %>%
inner_join(df, by=c("tractname"="geoid"))
subdf <- split(homs_rates %>% filter(city=="Chicago"), f = df$year)
p1 <- ggplot(subdf[[1]]) +
geom_sf(aes(fill=fatal_shootings), size=0.01) +
facet_wrap(~year, ncol = 1, labeller = labeller(VAR = "year")) +
theme_minimal() +
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
panel.grid.major = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
legend.key.size = unit(0.6, 'cm'),
legend.text = element_text(size=8),
strip.text = element_text(size=14)) +
scale_fill_gradient(low = "white", high = "indianred4", limits=c(0,62))
# do it for each "facet"
p2 <- p1 %+% subdf[[2]]
p3 = p2 %+% subdf[[3]]
p4 = p3 %+% subdf[[4]]
# here the plot
grid.arrange(p1,p2,p3,p4, nrow=1)
# here the plot
library(gridExtra)
grid.arrange(p1,p2,p3,p4, nrow=1)
p1 <- ggplot(subdf[[1]]) +
geom_sf(aes(fill=fatal_shootings), size=0.01) +
facet_wrap(~year, ncol = 1, labeller = labeller(VAR = "year")) +
theme_minimal() +
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
panel.grid.major = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
legend.key.size = unit(0.6, 'cm'),
legend.text = element_text(size=8),
strip.text = element_text(size=14)) +
scale_fill_gradient(low = "linen", high = "indianred4", limits=c(0,62))
# do it for each "facet"
p2 <- p1 %+% subdf[[2]]
p3 = p2 %+% subdf[[3]]
p4 = p3 %+% subdf[[4]]
# here the plot
library(gridExtra)
grid.arrange(p1,p2,p3,p4, nrow=1)
p1 <- ggplot(subdf[[1]]) +
geom_sf(aes(fill=fatal_shootings), size=0.01) +
facet_wrap(~year, ncol = 1, labeller = labeller(VAR = "year")) +
theme_minimal() +
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
panel.grid.major = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
legend.key.size = unit(0.6, 'cm'),
legend.text = element_text(size=8),
strip.text = element_text(size=14)) +
scale_fill_gradient(low = "linen", high = "indianred4", limits=c(0,62))
# do it for each "facet"
p2 <- p1 %+% subdf[[2]]
p3 = p2 %+% subdf[[3]]
p4 = p3 %+% subdf[[4]]
p5 = p4 %+% subdf[[5]]
p6 = p5 %+% subdf[[6]]
p7 = p6 %+% subdf[[7]]
# here the plot
library(gridExtra)
grid.arrange(p1,p2,p3,p4,p5,p6,p7, nrow=2)
head(tracts_df)
p1 <- ggplot(subdf[[1]]) +
geom_sf(aes(fill=fatal_shootings), size=0.01) +
facet_wrap(~year, ncol = 1, labeller = labeller(VAR = "year")) +
theme_minimal() +
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
panel.grid.major = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
legend.key.size = unit(0.6, 'cm'),
legend.text = element_text(size=8),
strip.text = element_text(size=20)) +
scale_fill_gradient(low = "linen", high = "indianred4", limits=c(0,62))
# do it for each "facet"
p2 <- p1 %+% subdf[[2]]
p3 = p2 %+% subdf[[3]]
p4 = p3 %+% subdf[[4]]
p5 = p4 %+% subdf[[5]]
p6 = p5 %+% subdf[[6]]
p7 = p6 %+% subdf[[7]]
# here the plot
library(gridExtra)
grid.arrange(p1,p2,p3,p4,p5,p6,p7, nrow=2)
p1 <- ggplot(subdf[[1]]) +
geom_sf(aes(fill=fatal_shootings), size=0.01) +
facet_wrap(~year, ncol = 1, labeller = labeller(VAR = "year")) +
theme_minimal() +
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
panel.grid.major = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
legend.key.size = unit(0.6, 'cm'),
legend.text = element_text(size=14),
strip.text = element_text(size=20)) +
scale_fill_gradient(low = "linen", high = "indianred4", limits=c(0,62))
# do it for each "facet"
p2 <- p1 %+% subdf[[2]]
p3 = p2 %+% subdf[[3]]
p4 = p3 %+% subdf[[4]]
p5 = p4 %+% subdf[[5]]
p6 = p5 %+% subdf[[6]]
p7 = p6 %+% subdf[[7]]
# here the plot
library(gridExtra)
grid.arrange(p1,p2,p3,p4,p5,p6,p7, nrow=2)
census_key <- "9a6cc5503c3c27953dafbe98ceece3fe9ea0b8ee"
current_fp <- dirname(rstudioapi::getSourceEditorContext()$path)
setwd(dirname(current_fp))
#------------------------------------------------------------
# DEPENDENCIES
#------------------------------------------------------------
library(tidycensus)
library(purrr)
library(stringr)
library(tidyverse)
library(dplyr)
library(tidyr)
library(sf)
library(tigris)
library(ggplot2)
library(grid)
library(gtable)
library(kableExtra)
library(gridExtra)
# to avoid conflicts with base packages:
library(conflicted)
conflict_prefer("filter", "dplyr")
conflict_prefer("lag", "dplyr")
source("./R/file_locations.R")
# load in all Helper functions
file.sources <- list.files(paste(file_locations$current_fp, file_locations$Helpers$`Helper Functions`, sep="/"),
pattern="*.R")
sapply(paste(paste(file_locations$current_fp, file_locations$Helpers$`Helper Functions`, sep="/"),
file.sources, sep="/"),
source, .GlobalEnv)
source(paste(file_locations$current_fp, "R/process_city_geographies.R", sep="/"))
process_city_geographies(file_locations, overwrite=T)
source(paste(file_locations$current_fp, "R/Chicago/process_demographics_Chicago.R", sep="/"))
source(paste(file_locations$current_fp, "R/Chicago/process_comp_disadv_Chicago.R", sep="/"))
process_demographics_Chicago(file_locations, population_cutoff=200, overwrite=T)
process_comp_disadv_Chicago(file_locations, overwrite=T)
source(paste(file_locations$current_fp, "R/Nation/process_fatal_shootings_Nation.R", sep="/"))
source(paste(file_locations$current_fp, "R/Nation/process_demographics_Nation.R", sep="/"))
source(paste(file_locations$current_fp, "R/Nation/process_comp_disadv_Nation.R", sep="/"))
process_fatal_shootings_nation(file_locations, overwrite=T)
process_demographics_nation(file_locations, population_cutoff=200, overwrite=T)
process_comp_disadv_Nation(file_locations, overwrite=T)
source(paste(file_locations$current_fp, "R/Chicago/Chicago_Analysis.R", sep="/"))
run_Chicago_analysis(file_locations)
source(paste(file_locations$current_fp, "R/Nation/National_Analysis.R", sep="/"))
run_National_analysis(file_locations)
